package org.greyhawk.samonitor.domain;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;

@Entity
@Table(name="S_FAGUI_FANWEI")
public class StatuteClassification implements Serializable{
	
    @PersistenceContext
    transient EntityManager entityManager;

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="S_FAGUI_FANWEI_ID")
	private Integer id;
	
	@Column(name="S_FAGUI_FANWEI_NAME")
	private String name;
	
	@Column(name="S_FAGUI_FANWEI_HID")
	private Integer hId;
	
	@Column(name="S_FAGUI_FANWEI_SORT")
	private Integer sort;
	
	@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="classification")
	private Set<Statute> statutes;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer gethId() {
		return hId;
	}

	public void sethId(Integer hId) {
		this.hId = hId;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public Set<Statute> getStatutes() {
		return statutes;
	}

	public void setStatutes(Set<Statute> statutes) {
		this.statutes = statutes;
	}
	
	public static final EntityManager entityManager() {
        EntityManager em = new Site().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }
	
	
	@SuppressWarnings("unchecked")
	public static List<StatuteClassification> findAllStatuteClassification(){
		String qlString = "from StatuteClassification";
		return StatuteClassification.entityManager().createQuery(qlString).getResultList();
	}
	
	public static StatuteClassification findStatuteClassificationById(Integer id){
		return StatuteClassification.entityManager().find(StatuteClassification.class, id);
	}
	
	
	
	

}
